<?php
	//引入配置文件和数据操作函数
	require '../public/config.php';
	require '../public/mysql.php';

	//接受操作
	$action = $_GET['a'];
	//判断是哪个操作
	switch ($action) {
		//执行登录的操作
		case 'login':
			//开启session
			session_start();
			$vcode = $_SESSION['code'];
			//获取用户的登录数据
			$name = $_POST['username'];
			$pass = $_POST['password'];
			$code = $_POST['code'];
			
		
			//判断用户名和密码是否正确
			//连接数据库
			$link = connect();
			if ($link['error']) {
				//查询用户的sql语句
				$sql = "select * from vip where username = '{$name}' and pass = '{$pass}'";
				//echo $sql;
				$result = query($link['mess'], $sql);
				$role =$result['0']['role'];
				if ($result != null) {
					//需要将用户的信息存到session
					$_SESSION['admin']['user'] = $name;
					$_SESSION['admin']['role'] =$role;
					header('location:../index.php');
				} else {
					echo "<script>alert('登录失败');location.href='./login.php'</script>";
					die();
				}
			}
		break;
		//退出操作
		case 'logout':
			session_start();
			//销毁session
			unset($_SESSION['admin']['user']);
			header('location:../index.php');
		break;

	
	}
?>